package org.nidy.erp.controller;

import org.nidy.erp.pojo.Employees;
import org.nidy.erp.service.ILoginService;
import org.nidy.erp.utils.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/login")
@CrossOrigin(origins = "*", maxAge = 3600)
public class LoginController {
    //    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
    @Autowired
    private ILoginService loginService;

    public LoginController(ILoginService loginService) {
        this.loginService = loginService;
    }

    /*
     * 登录校验
     */
    @PostMapping
    public ResponseResult CheckLogin(@RequestBody Employees employees) {
        Employees emp = loginService.checkLogin(employees);
        log.info("登录校验参数:{}", employees);
        log.info("登录校验返回结果:{}", emp);
        if (emp != null) {
            return ResponseResult.success(emp);
        } else {
            return ResponseResult.error("登录失败，用户名或密码错误");
        }
    }


}

